package com.listener;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

@WebListener
public class AllListener implements ServletContextListener, HttpSessionListener, HttpSessionAttributeListener {

    public AllListener() {
    }

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        InputStream resourceAsStream = AllListener.class.getClassLoader().getResourceAsStream("1.properties");
        Properties properties = new Properties();
        try {
            properties.load(resourceAsStream);
            String url = properties.getProperty("url");
            String[] split = url.split(",");
            sce.getServletContext().setAttribute("url",split);
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        /* This method is called when the servlet Context is undeployed or Application Server shuts down. */
    }

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        /* Session is created. */
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        /* Session is destroyed. */
    }

    @Override
    public void attributeAdded(HttpSessionBindingEvent sbe) {
        /* This method is called when an attribute is added to a session. */
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent sbe) {
        /* This method is called when an attribute is removed from a session. */
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent sbe) {
        /* This method is called when an attribute is replaced in a session. */
    }
}
